package com.itheima.youdianda.controller;

import com.itheima.youdianda.common.Result;
import com.itheima.youdianda.domain.YddAdvimg;
import com.itheima.youdianda.service.YddAdvimgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Hakuna Matata
 * @date 2022-09-07-10:59
 */
@RestController
@RequestMapping("ydd_advimg")
public class YddAdvImgController {

    @Autowired
    private YddAdvimgService yddAdvimgService;

    /**
     * 广告图详情
     *
     * @param id
     * @return
     */
    @GetMapping("rowInfo")
    public Result getById(Integer id) {
        YddAdvimg yddAdvimg = yddAdvimgService.getById(id);
        return Result.ok(yddAdvimg);
    }

    /**
     * 广告图列表 -- 分页
     */
    @GetMapping("list")
    public Result pageByList(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                             @RequestParam(value = "limit", required = false, defaultValue = "5") Integer limit,
                             String advimgdesc, String advimgpos) {
        return yddAdvimgService.pageByList(page, limit, advimgdesc, advimgpos);
    }

    /**
     * 修改
     *
     * @param yddAdvimg
     * @return
     */
    @PostMapping("update")
    public Result updateAdvImg(@RequestBody YddAdvimg yddAdvimg) {
        yddAdvimgService.updateById(yddAdvimg);
        return Result.ok("修改成功!");
    }

    @GetMapping("del")
    public Result deleteAdvImg(Integer id) {
        boolean flag = yddAdvimgService.removeById(id);
        return Result.ok(flag ? "删除成功!" : "删除失败!");
    }

    /**
     * 广告图 -- 添加
     * @param yddAdvimg
     * @return
     */
    @GetMapping("add")
    public Result add(@RequestBody YddAdvimg yddAdvimg) {
        yddAdvimgService.add(yddAdvimg);
        return Result.ok("添加成功!");
    }



}
